﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Project
{
    public partial class addItem : Form
    {
        private OleDbConnection bookConn;
        private OleDbCommand oleDbCmd = new OleDbCommand();
        //parameter from mdsaputra.udl




        private String connParam = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Properties.Settings.Default.database + ";Persist Security Info=False";

       


        public addItem()
        {
            bookConn = new OleDbConnection(connParam); 
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bookConn.Open();
            oleDbCmd.Connection = bookConn;
            oleDbCmd.CommandText = "insert into item (iName, iCategory, iDesc, iStatus) values ('" + this.txtName.Text + "','" + this.cbCategory.Text + "','" + this.txtDesc.Text + "','" + this.cbStatus.Text + "');";
            try
            {
                int temp = oleDbCmd.ExecuteNonQuery();
                if (temp > 0)
                {
                    txtName.Text = null;
                    cbCategory.Text = null;
                    txtDesc.Text = null;
                    cbStatus.Text = null;
                    
                    DialogResult dialogResult = MessageBox.Show("Item successfully added.\n\nAdd another Item.", "", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                //do something
            }
            else if (dialogResult == DialogResult.No)
            {
                this.Close();
            }
                }
                else
                {
                    MessageBox.Show("Record Fail to Added");
                }
            }
             catch
            {
                MessageBox.Show("Record Fail to Added");
            }
            bookConn.Close();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\deb.mdb;Persist Security Info=False";
        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            this.Close();
        } 
        
       
        }
    }

